home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / Sound / LAME / WarpOS / src / include / lame.h next >
Encoding:
C/C++ Source or Header  |  2001-06-18  |  30.8 KB  |  838 lines

  1. /*
  2.  *    Interface to MP3 LAME encoding engine
  3.  *
  4.  *    Copyright (c) 1999 Mark Taylor
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2, or (at your option)
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; see the file COPYING.  If not, write to
  18.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. /* $Id: lame.h,v 1.85 2001/06/18 18:51:52 markt Exp $ */
  22.  
  23. #ifndef LAME_LAME_H
  24. #define LAME_LAME_H
  25.  
  26. #include <stdio.h>
  27. #include <stdarg.h>
  28.  
  29. #if defined(__cplusplus)
  30. extern "C" {
  31. #endif
  32.  
  33. #if defined(WIN32)
  34. #undef CDECL
  35. #define CDECL _cdecl
  36. #else
  37. #define CDECL
  38. #endif
  39.  
  40.  
  41. typedef enum vbr_mode_e {
  42.   vbr_off=0,
  43.   vbr_mt,
  44.   vbr_rh,
  45.   vbr_abr,
  46.   vbr_mtrh,
  47.   vbr_max_indicator,    /* Don't use this! It's used for sanity checks.       */
  48.   vbr_default=vbr_rh  /* change this to change the default VBR mode of LAME */
  49. } vbr_mode;
  50.  
  51.  
  52. /* MPEG modes */
  53. typedef enum MPEG_mode_e {
  54.   STEREO = 0,
  55.   JOINT_STEREO,
  56.   DUAL_CHANNEL,   /* LAME doesn't supports this! */
  57.   MONO,
  58.   NOT_SET,
  59.   MAX_INDICATOR   /* Don't use this! It's used for sanity checks. */ 
  60. } MPEG_mode;
  61.  
  62. /* Padding types */
  63. typedef enum Padding_type_e {
  64.   PAD_NO = 0,
  65.   PAD_ALL,
  66.   PAD_ADJUST,
  67.   PAD_MAX_INDICATOR   /* Don't use this! It's used for sanity checks. */
  68. } Padding_type;
  69.  
  70.  
  71.  
  72. struct lame_global_struct;
  73. typedef struct lame_global_struct lame_global_flags;
  74. typedef lame_global_flags *lame_t;
  75.  
  76.  
  77.  
  78.  
  79. /***********************************************************************
  80.  *
  81.  *  The LAME API
  82.  *  These functions should be called, in this order, for each
  83.  *  MP3 file to be encoded 
  84.  *
  85.  ***********************************************************************/
  86.  
  87.  
  88. /*
  89.  * REQUIRED:
  90.  * initialize the encoder.  sets default for all encoder paramters,
  91.  * returns -1 if some malloc()'s failed
  92.  * otherwise returns 0
  93.  */
  94. lame_global_flags * CDECL lame_init(void);
  95. /* obsolete version */
  96. int CDECL lame_init_old(lame_global_flags *);
  97.  
  98.  
  99. /*
  100.  * OPTIONAL:
  101.  * set as needed to override defaults
  102.  */
  103.  
  104. /********************************************************************
  105.  *  input stream description
  106.  ***********************************************************************/
  107. // number of samples.  default = 2^32-1  
  108. int CDECL lame_set_num_samples(lame_global_flags *, unsigned long);
  109. unsigned long CDECL lame_get_num_samples(const lame_global_flags *);
  110.  
  111. // input sample rate in Hz.  default = 44100hz
  112. int CDECL lame_set_in_samplerate(lame_global_flags *, int);
  113. int CDECL lame_get_in_samplerate(const lame_global_flags *);
  114.  
  115. // number of channels in input stream. default=2 
  116. int CDECL lame_set_num_channels(lame_global_flags *, int);
  117. int CDECL lame_get_num_channels(const lame_global_flags *);
  118.  
  119. // scale the input by this amount before encoding.  default=0 (disabled)
  120. // (not used by decoding routines)
  121. int CDECL lame_set_scale(lame_global_flags *, float);
  122. float CDECL lame_get_scale(const lame_global_flags *);
  123.  
  124. // output sample rate in Hz.  default = 0, which means LAME picks best value 
  125. // based on the amount of compression.  MPEG only allows:
  126. // MPEG1    32, 44.1,   48khz
  127. // MPEG2    16, 22.05,  24
  128. // MPEG2.5   8, 11.025, 12
  129. // (not used by decoding routines)
  130. int CDECL lame_set_out_samplerate(lame_global_flags *, int);
  131. int CDECL lame_get_out_samplerate(const lame_global_flags *);
  132.  
  133.  
  134. /********************************************************************
  135.  *  general control parameters
  136.  ***********************************************************************/
  137. // 1=cause LAME to collect data for an MP3 frame analzyer. default=0
  138. int CDECL lame_set_analysis(lame_global_flags *, int);
  139. int CDECL lame_get_analysis(const lame_global_flags *);
  140.  
  141. // 1 = write a Xing VBR header frame.
  142. // default = 1 for VBR/ABR modes, 0 for CBR mode
  143. // this variable must have been added by a Hungarian notation Windows programmer :-)
  144. int CDECL lame_set_bWriteVbrTag(lame_global_flags *, int);
  145. int CDECL lame_get_bWriteVbrTag(const lame_global_flags *);
  146.  
  147. // 1=decode only.  use lame/mpglib to convert mp3/ogg to wav.  default=0
  148. int CDECL lame_set_decode_only(lame_global_flags *, int);
  149. int CDECL lame_get_decode_only(const lame_global_flags *);
  150.  
  151. // 1=encode a Vorbis .ogg file.  default=0
  152. int CDECL lame_set_ogg(lame_global_flags *, int);
  153. int CDECL lame_get_ogg(const lame_global_flags *);
  154.  
  155. // internal algorithm selection.  True quality is determined by the bitrate
  156. // but this variable will effect quality by selecting expensive or cheap algorithms.
  157. // quality=0..9.  0=best (very slow).  9=worst.  
  158. // recommended:  2     near-best quality, not too slow
  159. //               5     good quality, fast
  160. //               7     ok quality, really fast
  161. int CDECL lame_set_quality(lame_global_flags *, int);
  162. int CDECL lame_get_quality(const lame_global_flags *);
  163.  
  164. // mode = 0,1,2,3 = stereo, jstereo, dual channel (not supported), mono
  165. // default: lame picks based on compression ration and input channels
  166. int CDECL lame_set_mode(lame_global_flags *, MPEG_mode);
  167. MPEG_mode CDECL lame_get_mode(const lame_global_flags *);
  168.  
  169. // mode_automs.  Us a M/S mode with a switching threshold based on 
  170. // compression ratio
  171. // default = 0 (disabled)
  172. int CDECL lame_set_mode_automs(lame_global_flags *, int);
  173. int CDECL lame_get_mode_automs(const lame_global_flags *);
  174.  
  175. // force_ms.  Force M/S for all frames.  For testing only.
  176. // default = 0 (disabled)
  177. int CDECL lame_set_force_ms(lame_global_flags *, int);
  178. int CDECL lame_get_force_ms(const lame_global_flags *);
  179.  
  180. // use free_format?  default = 0 (disabled)
  181. int CDECL lame_set_free_format(lame_global_flags *, int);
  182. int CDECL lame_get_free_format(const lame_global_flags *);
  183.  
  184. /*
  185.  * OPTIONAL:
  186.  * Set printf like error/debug/message reporting functions.
  187.  * The second argument has to be a pointer to a function which looks like
  188.  *   void my_debugf(const char *format, va_list ap)
  189.  *   {
  190.  *       (void) vfprintf(stdout, format, ap);
  191.  *   }
  192.  * If you use NULL as the value of the pointer in the set function, the
  193.  * lame buildin function will be used (prints to stderr).
  194.  * To quiet any output you have to replace the body of the example function
  195.  * with just "return;" and use it in the set function.
  196.  */
  197. int CDECL lame_set_errorf(lame_global_flags *,
  198.                           void (*func)(const char *, va_list));
  199. int CDECL lame_set_debugf(lame_global_flags *,
  200.                           void (*func)(const char *, va_list));
  201. int CDECL lame_set_msgf  (lame_global_flags *,
  202.                           void (*func)(const char *, va_list));
  203.  
  204.  
  205.  
  206. /* set one of brate compression ratio.  default is compression ratio of 11.  */
  207. int CDECL lame_set_brate(lame_global_flags *, int);
  208. int CDECL lame_get_brate(const lame_global_flags *);
  209. int CDECL lame_set_compression_ratio(lame_global_flags *, float);
  210. float CDECL lame_get_compression_ratio(const lame_global_flags *);
  211.  
  212. /********************************************************************
  213.  *  frame params
  214.  ***********************************************************************/
  215. // mark as copyright.  default=0
  216. int CDECL lame_set_copyright(lame_global_flags *, int);
  217. int CDECL lame_get_copyright(const lame_global_flags *);
  218.  
  219. // mark as original.  default=1
  220. int CDECL lame_set_original(lame_global_flags *, int);
  221. int CDECL lame_get_original(const lame_global_flags *);
  222.  
  223. // error_protection.  Use 2 bytes from each fraome for CRC checksum. default=0
  224. int CDECL lame_set_error_protection(lame_global_flags *, int);
  225. int CDECL lame_get_error_protection(const lame_global_flags *);
  226.  
  227. // padding_type.  0=pad no frames  1=pad all frames 2=adjust padding(default)
  228. int CDECL lame_set_padding_type(lame_global_flags *, Padding_type);
  229. Padding_type CDECL lame_get_padding_type(const lame_global_flags *);
  230.  
  231. // MP3 'private extension' bit  Meaningless
  232. int CDECL lame_set_extension(lame_global_flags *, int);
  233. int CDECL lame_get_extension(const lame_global_flags *);
  234.  
  235. // enforce strict ISO complience.  default=0
  236. int CDECL lame_set_strict_ISO(lame_global_flags *, int);
  237. int CDECL lame_get_strict_ISO(const lame_global_flags *);
  238.  
  239.  
  240. /********************************************************************
  241.  * quantization/noise shaping 
  242.  ***********************************************************************/
  243.  
  244. // disable the bit reservoir. For testing only. default=0
  245. int CDECL lame_set_disable_reservoir(lame_global_flags *, int);
  246. int CDECL lame_get_disable_reservoir(const lame_global_flags *);
  247.  
  248. // select a different "best quantization" function. default=0 
  249. int CDECL lame_set_experimentalX(lame_global_flags *, int);
  250. int CDECL lame_get_experimentalX(const lame_global_flags *);
  251.  
  252. // another experimental option.  for testing only
  253. int CDECL lame_set_experimentalY(lame_global_flags *, int);
  254. int CDECL lame_get_experimentalY(const lame_global_flags *);
  255.  
  256. // another experimental option.  for testing only
  257. int CDECL lame_set_experimentalZ(lame_global_flags *, int);
  258. int CDECL lame_get_experimentalZ(const lame_global_flags *);
  259.  
  260. // Naoki's psycho acoustic model.  default=0
  261. int CDECL lame_set_exp_nspsytune(lame_global_flags *, int);
  262. int CDECL lame_get_exp_nspsytune(const lame_global_flags *);
  263.  
  264.  
  265.  
  266. /********************************************************************
  267.  * VBR control
  268.  ***********************************************************************/
  269. // Types of VBR.  default = vbr_off = CBR
  270. int CDECL lame_set_VBR(lame_global_flags *, vbr_mode);
  271. vbr_mode CDECL lame_get_VBR(const lame_global_flags *);
  272.  
  273. // VBR quality level.  0=highest  9=lowest 
  274. int CDECL lame_set_VBR_q(lame_global_flags *, int);
  275. int CDECL lame_get_VBR_q(const lame_global_flags *);
  276.  
  277. // Ignored except for VBR=vbr_abr (ABR mode)
  278. int CDECL lame_set_VBR_mean_bitrate_kbps(lame_global_flags *, int);
  279. int CDECL lame_get_VBR_mean_bitrate_kbps(const lame_global_flags *);
  280.  
  281. int CDECL lame_set_VBR_min_bitrate_kbps(lame_global_flags *, int);
  282. int CDECL lame_get_VBR_min_bitrate_kbps(const lame_global_flags *);
  283.  
  284. int CDECL lame_set_VBR_max_bitrate_kbps(lame_global_flags *, int);
  285. int CDECL lame_get_VBR_max_bitrate_kbps(const lame_global_flags *);
  286.  
  287. // 1=stricetly enforce VBR_min_bitrate.  Normally it will be violated for
  288. // analog silence
  289. int CDECL lame_set_VBR_hard_min(lame_global_flags *, int);
  290. int CDECL lame_get_VBR_hard_min(const lame_global_flags *);
  291.  
  292.  
  293. /********************************************************************
  294.  * Filtering control
  295.  ***********************************************************************/
  296. // freq in Hz to apply lowpass. Default = 0 = lame chooses.  -1 = disabled
  297. int CDECL lame_set_lowpassfreq(lame_global_flags *, int);
  298. int CDECL lame_get_lowpassfreq(const lame_global_flags *);
  299. // width of transition band, in Hz.  Default = one polyphase filter band
  300. int CDECL lame_set_lowpasswidth(lame_global_flags *, int);
  301. int CDECL lame_get_lowpasswidth(const lame_global_flags *);
  302.  
  303. // freq in Hz to apply highpass. Default = 0 = lame chooses.  -1 = disabled
  304. int CDECL lame_set_highpassfreq(lame_global_flags *, int);
  305. int CDECL lame_get_highpassfreq(const lame_global_flags *);
  306. // width of transition band, in Hz.  Default = one polyphase filter band
  307. int CDECL lame_set_highpasswidth(lame_global_flags *, int);
  308. int CDECL lame_get_highpasswidth(const lame_global_flags *);
  309.  
  310.  
  311. /********************************************************************
  312.  * psycho acoustics and other arguments which you should not change 
  313.  * unless you know what you are doing
  314.  ***********************************************************************/
  315. // only use ATH for masking
  316. int CDECL lame_set_ATHonly(lame_global_flags *, int);
  317. int CDECL lame_get_ATHonly(const lame_global_flags *);
  318.  
  319. // only use ATH for short blocks
  320. int CDECL lame_set_ATHshort(lame_global_flags *, int);
  321. int CDECL lame_get_ATHshort(const lame_global_flags *);
  322.  
  323. // disable ATH
  324. int CDECL lame_set_noATH(lame_global_flags *, int);
  325. int CDECL lame_get_noATH(const lame_global_flags *);
  326.  
  327. // select ATH formula
  328. int CDECL lame_set_ATHtype(lame_global_flags *, int);
  329. int CDECL lame_get_ATHtype(const lame_global_flags *);
  330.  
  331. // lower ATH by this many db
  332. int CDECL lame_set_ATHlower(lame_global_flags *, float);
  333. float CDECL lame_get_ATHlower(const lame_global_flags *);
  334.  
  335. // select adaptive ATH type
  336. int CDECL lame_set_adjust_type( lame_global_flags *, int);
  337. int CDECL lame_get_adjust_type( const lame_global_flags *);
  338.  
  339. // select adaptive ATH level adjustment scheme
  340. int CDECL lame_set_adapt_thres_type( lame_global_flags *, int);
  341. int CDECL lame_get_adapt_thres_type( const lame_global_flags *);
  342.  
  343. // adjust (in dB) the point below which adaptive ATH level adjustment occurs
  344. int CDECL lame_set_adapt_thres_level( lame_global_flags *, float);
  345. float CDECL lame_get_adapt_thres_level( const lame_global_flags* );
  346.  
  347. // predictability limit (ISO tonality formula)
  348. int CDECL lame_set_cwlimit(lame_global_flags *, int);
  349. int CDECL lame_get_cwlimit(const lame_global_flags *);
  350.  
  351. // allow blocktypes to differ between channels?
  352. // default: 0 for jstereo, 1 for stereo
  353. int CDECL lame_set_allow_diff_short(lame_global_flags *, int);
  354. int CDECL lame_get_allow_diff_short(const lame_global_flags *);
  355.  
  356. // use temporal masking effect (default = 1)
  357. int CDECL lame_set_useTemporal(lame_global_flags *, int);
  358. int CDECL lame_get_useTemporal(const lame_global_flags *);
  359.  
  360. // disable short blocks
  361. int CDECL lame_set_no_short_blocks(lame_global_flags *, int);
  362. int CDECL lame_get_no_short_blocks(const lame_global_flags *);
  363.  
  364. /* Input PCM is emphased PCM (for instance from one of the rarely
  365.    emphased CDs), it is STRONGLY not recommended to use this, because
  366.    psycho does not take it into account, and last but not least many decoders
  367.    ignore these bits */
  368. int CDECL lame_set_emphasis(lame_global_flags *, int);
  369. int CDECL lame_get_emphasis(const lame_global_flags *);
  370.  
  371.  
  372.  
  373. /************************************************************************/
  374. /* internal variables, cannot be set...                                 */
  375. /* provided because they may be of use to calling application           */
  376. /************************************************************************/
  377. // version  0=MPEG-2  1=MPEG-1  (2=MPEG-2.5)    
  378. int CDECL lame_get_version(const lame_global_flags *);
  379.  
  380. // encoder delay
  381. int CDECL lame_get_encoder_delay(const lame_global_flags *);
  382.  
  383. // size of MPEG frame
  384. int CDECL lame_get_framesize(const lame_global_flags *);
  385.  
  386. // number of PCM samples buffered, but not yet encoded to mp3 data.
  387. int CDECL lame_get_mf_samples_to_encode( const lame_global_flags*  gfp );
  388.  
  389. // size (bytes) of mp3 data buffered, but not yet encoded.
  390. // this is the number of bytes which would be output by a call to 
  391. // lame_encode_flush_nogap.  NOTE: lame_encode_flush() will return
  392. // more bytes than this because it will encode the reamining buffered
  393. // PCM samples before flushing the mp3 buffers.
  394. int CDECL lame_get_size_mp3buffer( const lame_global_flags*  gfp );
  395.  
  396. // number of frames encoded so far
  397. int CDECL lame_get_frameNum(const lame_global_flags *);
  398.  
  399. // lame's estimate of the total number of frames to be encoded
  400. // only valid if calling program set num_samples 
  401. int CDECL lame_get_totalframes(const lame_global_flags *);
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410. /*
  411.  * REQUIRED:
  412.  * sets more internal configuration based on data provided above.
  413.  * returns -1 if something failed.
  414.  */
  415. int CDECL lame_init_params(lame_global_flags *);
  416.  
  417.  
  418. /*
  419.  * OPTIONAL:
  420.  * get the version number, in a string. of the form:  
  421.  * "3.63 (beta)" or just "3.63". 
  422.  */
  423. const char*  CDECL get_lame_version       ( void );
  424. const char*  CDECL get_lame_short_version ( void );
  425. const char*  CDECL get_psy_version        ( void );
  426. const char*  CDECL get_mp3x_version       ( void );
  427. const char*  CDECL get_lame_url           ( void );
  428.  
  429. /*
  430.  * OPTIONAL:
  431.  * get the version numbers in numerical form.
  432.  */
  433. typedef struct {
  434.     /* generic LAME version */
  435.     int major;
  436.     int minor;
  437.     int alpha;               /* 0 if not an alpha version                  */
  438.     int beta;                /* 0 if not a beta version                    */
  439.  
  440.     /* version of the psy model */
  441.     int psy_major;
  442.     int psy_minor;
  443.     int psy_alpha;           /* 0 if not an alpha version                  */
  444.     int psy_beta;            /* 0 if not a beta version                    */
  445.  
  446.     /* compile time features */
  447.     const char *features;    /* Don't make assumptions about the contents! */
  448. } lame_version_t;
  449. void CDECL get_lame_version_numerical ( lame_version_t *const );
  450.  
  451.  
  452. /*
  453.  * OPTIONAL:
  454.  * print internal lame configuration to message handler
  455.  */
  456. void CDECL lame_print_config(const lame_global_flags*  gfp);
  457.  
  458. void CDECL lame_print_internals( const lame_global_flags *gfp);
  459.  
  460.  
  461. /*
  462.  * input pcm data, output (maybe) mp3 frames.
  463.  * This routine handles all buffering, resampling and filtering for you.
  464.  * 
  465.  * return code     number of bytes output in mp3buf. Can be 0 
  466.  *                 -1:  mp3buf was too small
  467.  *                 -2:  malloc() problem
  468.  *                 -3:  lame_init_params() not called
  469.  *                 -4:  psycho acoustic problems 
  470.  *                 -5:  ogg cleanup encoding error
  471.  *                 -6:  ogg frame encoding error
  472.  *
  473.  * The required mp3buf_size can be computed from num_samples, 
  474.  * samplerate and encoding rate, but here is a worst case estimate:
  475.  *
  476.  * mp3buf_size in bytes = 1.25*num_samples + 7200
  477.  *
  478.  * I think a tighter bound could be:  (mt, March 2000)
  479.  * MPEG1:
  480.  *    num_samples*(bitrate/8)/samplerate + 4*1152*(bitrate/8)/samplerate + 512
  481.  * MPEG2:
  482.  *    num_samples*(bitrate/8)/samplerate + 4*576*(bitrate/8)/samplerate + 256
  483.  *
  484.  * but test first if you use that!
  485.  *
  486.  * set mp3buf_size = 0 and LAME will not check if mp3buf_size is
  487.  * large enough.
  488.  *
  489.  * NOTE:
  490.  * if gfp->num_channels=2, but gfp->mode = 3 (mono), the L & R channels
  491.  * will be averaged into the L channel before encoding only the L channel
  492.  * This will overwrite the data in buffer_l[] and buffer_r[].
  493.  * 
  494. */
  495. int CDECL lame_encode_buffer (
  496.         lame_global_flags*  gfp,           /* global context handle         */
  497.         const short int     buffer_l [],   /* PCM data for left channel     */
  498.         const short int     buffer_r [],   /* PCM data for right channel    */
  499.         const int           nsamples,      /* number of samples per channel */
  500.         unsigned char*      mp3buf,        /* pointer to encoded MP3 stream */
  501.         const int           mp3buf_size ); /* number of valid octets in this
  502.                                               stream                        */
  503.  
  504. /*
  505.  * as above, but input has L & R channel data interleaved.
  506.  * NOTE: 
  507.  * num_samples = number of samples in the L (or R)
  508.  * channel, not the total number of samples in pcm[]  
  509.  */
  510. int CDECL lame_encode_buffer_interleaved(
  511.         lame_global_flags*  gfp,           /* global context handlei        */
  512.         short int           pcm[],         /* PCM data for left and right
  513.                                               channel, interleaved          */
  514.         int                 num_samples,   /* number of samples per channel,
  515.                                               _not_ number of samples in
  516.                                               pcm[]                         */
  517.         unsigned char*      mp3buf,        /* pointer to encoded MP3 stream */
  518.         int                 mp3buf_size ); /* number of valid octets in this
  519.                                               stream                        */
  520.  
  521.  
  522. /* as lame_encode_buffer, but for 'float's */
  523. int CDECL lame_encode_buffer_float(
  524.         lame_global_flags*  gfp,           /* global context handle         */
  525.         const float     buffer_l [],       /* PCM data for left channel     */
  526.         const float     buffer_r [],       /* PCM data for right channel    */
  527.         const int           nsamples,      /* number of samples per channel */
  528.         unsigned char*      mp3buf,        /* pointer to encoded MP3 stream */
  529.         const int           mp3buf_size ); /* number of valid octets in this
  530.                                               stream                        */
  531.  
  532. /* as lame_encode_buffer, but for int's */
  533. int CDECL lame_encode_buffer_int(
  534.         lame_global_flags*  gfp,           /* global context handle         */
  535.         const int      buffer_l [],       /* PCM data for left channel     */
  536.         const int      buffer_r [],       /* PCM data for right channel    */
  537.         const int           nsamples,      /* number of samples per channel */
  538.         unsigned char*      mp3buf,        /* pointer to encoded MP3 stream */
  539.         const int           mp3buf_size ); /* number of valid octets in this
  540.                                               stream                        */
  541.  
  542. /* as lame_encode_buffer, but for long's */
  543. int CDECL lame_encode_buffer_long(
  544.         lame_global_flags*  gfp,           /* global context handle         */
  545.         const long     buffer_l [],       /* PCM data for left channel     */
  546.         const long     buffer_r [],       /* PCM data for right channel    */
  547.         const int           nsamples,      /* number of samples per channel */
  548.         unsigned char*      mp3buf,        /* pointer to encoded MP3 stream */
  549.         const int           mp3buf_size ); /* number of valid octets in this
  550.                                               stream                        */
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557. /*
  558.  * REQUIRED:
  559.  * lame_encode_flush will flush the intenal PCM buffers, padding with 
  560.  * 0's to make sure the final frame is complete, and then flush
  561.  * the internal MP3 buffers, and thus may return a 
  562.  * final few mp3 frames.  'mp3buf' should be at least 7200 bytes long
  563.  * to hold all possible emitted data.
  564.  *
  565.  * will also write id3v1 tags (if any) into the bitstream       
  566.  *
  567.  * return code = number of bytes output to mp3buf. Can be 0
  568.  */
  569. int CDECL lame_encode_flush(
  570.         lame_global_flags *  gfp,    /* global context handle                 */
  571.         unsigned char*       mp3buf, /* pointer to encoded MP3 stream         */
  572.         int                  size);  /* number of valid octets in this stream */
  573.  
  574. /*
  575.  * OPTIONAL:
  576.  * lame_encode_flush_nogap will flush the internal mp3 buffers and pad
  577.  * the last frame with ancillary data so it is a complete mp3 frame.
  578.  * 
  579.  * 'mp3buf' should be at least 7200 bytes long
  580.  * to hold all possible emitted data.
  581.  *
  582.  * After a call to this routine, the outputed mp3 data is complete, but
  583.  * you may continue to encode new PCM samples and write future mp3 data
  584.  * to a different file.  The two mp3 files will play back with no gaps
  585.  * if they are concatenated together.
  586.  *
  587.  * This routine will NOT write id3v1 tags into the bitstream.
  588.  *
  589.  * return code = number of bytes output to mp3buf. Can be 0
  590.  */
  591. int CDECL lame_encode_flush_nogap(
  592.         lame_global_flags *  gfp,    /* global context handle                 */
  593.         unsigned char*       mp3buf, /* pointer to encoded MP3 stream         */
  594.         int                  size);  /* number of valid octets in this stream */
  595.  
  596. /*
  597.  * OPTIONAL:
  598.  * Normally, this is called by lame_init_params().  It writes id3v2 and
  599.  * Xing headers into the front of the bitstream, and sets frame counters
  600.  * and bitrate histogram data to 0.  You can also call this after 
  601.  * lame_encode_flush_nogap().  
  602.  */
  603. int CDECL lame_init_bitstream(
  604.         lame_global_flags *  gfp);    /* global context handle                 */
  605.  
  606.  
  607.  
  608. /*
  609.  * OPTIONAL:    some simple statistics
  610.  * a bitrate histogram to visualize the distribution of used frame sizes
  611.  * a stereo mode histogram to visualize the distribution of used stereo
  612.  *   modes, useful in joint-stereo mode only
  613.  *   0: LR    left-right encoded
  614.  *   1: LR-I  left-right and intensity encoded (currently not supported)
  615.  *   2: MS    mid-side encoded
  616.  *   3: MS-I  mid-side and intensity encoded (currently not supported)
  617.  *
  618.  * attention: don't call them after lame_encode_finish
  619.  * suggested: lame_encode_flush -> lame_*_hist -> lame_close
  620.  */
  621.  
  622. void CDECL lame_bitrate_hist( 
  623.         const lame_global_flags *const gfp, 
  624.               int                      bitrate_count[14] );
  625. void CDECL lame_bitrate_kbps( 
  626.         const lame_global_flags *const gfp, 
  627.               int                      bitrate_kbps [14] );
  628. void CDECL lame_stereo_mode_hist( 
  629.         const lame_global_flags *const gfp, 
  630.               int                      stereo_mode_count[4] );
  631.  
  632. void CDECL lame_bitrate_stereo_mode_hist ( 
  633.         const lame_global_flags*  gfp, 
  634.         int  bitrate_stmode_count [14] [4] );
  635.  
  636.  
  637. /*
  638.  * OPTIONAL:
  639.  * lame_mp3_tags_fid will append a Xing VBR tag to the mp3 file with file
  640.  * pointer fid.  These calls perform forward and backwards seeks, so make
  641.  * sure fid is a real file.  Make sure lame_encode_flush has been called,
  642.  * and all mp3 data has been written to the file before calling this
  643.  * function.
  644.  * NOTE:
  645.  * if VBR  tags are turned off by the user, or turned off by LAME because
  646.  * the output is not a regular file, this call does nothing
  647. */
  648. void CDECL lame_mp3_tags_fid(lame_global_flags *,FILE* fid);
  649.  
  650.  
  651. /*
  652.  * REQUIRED:
  653.  * final call to free all remaining buffers
  654.  */
  655. int  CDECL lame_close (lame_global_flags *);
  656.  
  657. /*
  658.  * OBSOLETE:
  659.  * lame_encode_finish combines lame_encode_flush() and lame_close() in
  660.  * one call.  However, once this call is made, the statistics routines
  661.  * will no longer work because the data will have been cleared
  662.  */
  663. int CDECL lame_encode_finish(
  664.         lame_global_flags*  gfp,
  665.         unsigned char*      mp3buf,
  666.         int                 size );
  667.  
  668.  
  669.  
  670.  
  671.  
  672.  
  673.  
  674. /*********************************************************************
  675.  *
  676.  * decoding 
  677.  *
  678.  * a simple interface to mpglib, part of mpg123, is also included if
  679.  * libmp3lame is compiled with HAVE_MPGLIB
  680.  *
  681.  *********************************************************************/
  682. typedef struct {
  683.   int header_parsed;   /* 1 if header was parsed and following data was
  684.                           computed                                       */
  685.   int stereo;          /* number of channels                             */
  686.   int samplerate;      /* sample rate                                    */
  687.   int bitrate;         /* bitrate                                        */
  688.   int mode;            /* mp3 frame type                                 */
  689.   int mode_ext;        /* mp3 frame type                                 */
  690.   int framesize;       /* number of samples per mp3 frame                */
  691.  
  692.   /* this data is only computed if mpglib detects a Xing VBR header */
  693.   unsigned long nsamp; /* number of samples in mp3 file.                 */
  694.   int totalframes;     /* total number of frames in mp3 file             */
  695.  
  696.   /* this data is not currently computed by the mpglib routines */
  697.   int framenum;        /* frames decoded counter                         */
  698. } mp3data_struct;
  699.  
  700.  
  701. /* required call to initialize decoder */
  702. int CDECL lame_decode_init(void);
  703.  
  704. /*********************************************************************
  705.  * input 1 mp3 frame, output (maybe) pcm data.  
  706.  * lame_decode() return code:
  707.  *   -1: error
  708.  *    0: need more data
  709.  *  n>0: size of pcm output
  710.  *********************************************************************/
  711. int CDECL lame_decode(
  712.         unsigned char *  mp3buf,
  713.         int              len,
  714.         short            pcm_l[],
  715.         short            pcm_r[] );
  716.  
  717. /* same as lame_decode, and also returns mp3 header data */
  718. int CDECL lame_decode_headers(
  719.         unsigned char*   mp3buf,
  720.         int              len,
  721.         short            pcm_l[],
  722.         short            pcm_r[],
  723.         mp3data_struct*  mp3data );
  724.  
  725. /* same as lame_decode, but returns at most one frame */
  726. int CDECL lame_decode1(
  727.         unsigned char*  mp3buf,
  728.         int             len,
  729.         short           pcm_l[],
  730.         short           pcm_r[] );
  731.  
  732. /* same as lame_decode1, but returns at most one frame and mp3 header data */
  733. int CDECL lame_decode1_headers(
  734.         unsigned char*   mp3buf,
  735.         int              len,
  736.         short            pcm_l[],
  737.         short            pcm_r[],
  738.         mp3data_struct*  mp3data );
  739.  
  740.  
  741.  
  742.  
  743.  
  744. /*********************************************************************
  745.  *
  746.  * id3tag stuff
  747.  *
  748.  *********************************************************************/
  749.  
  750. /*
  751.  * id3tag.h -- Interface to write ID3 version 1 and 2 tags.
  752.  *
  753.  * Copyright (C) 2000 Don Melton.
  754.  *
  755.  * This library is free software; you can redistribute it and/or
  756.  * modify it under the terms of the GNU Library General Public
  757.  * License as published by the Free Software Foundation; either
  758.  * version 2 of the License, or (at your option) any later version.
  759.  *
  760.  * This library is distributed in the hope that it will be useful,
  761.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  762.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  763.  * Library General Public License for more details.
  764.  *
  765.  * You should have received a copy of the GNU Library General Public
  766.  * License along with this library; if not, write to the Free Software
  767.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  768.  */
  769.  
  770. /* utility to obtain alphabetically sorted list of genre names with numbers */
  771. extern void id3tag_genre_list(
  772.         void (*handler)(int, const char *, void *),
  773.         void*  cookie);
  774.  
  775. extern void id3tag_init   (lame_global_flags *gfp);
  776.  
  777. /* force addition of version 2 tag */
  778. extern void id3tag_add_v2   (lame_global_flags *gfp);
  779.  
  780. /* add only a version 1 tag */
  781. extern void id3tag_v1_only  (lame_global_flags *gfp);
  782.  
  783. /* add only a version 2 tag */
  784. extern void id3tag_v2_only  (lame_global_flags *gfp);
  785.  
  786. /* pad version 1 tag with spaces instead of nulls */
  787. extern void id3tag_space_v1 (lame_global_flags *gfp);
  788.  
  789. /* pad version 2 tag with extra 128 bytes */
  790. extern void id3tag_pad_v2   (lame_global_flags *gfp);
  791.  
  792. extern void id3tag_set_title(
  793.         lame_global_flags*  gfp,
  794.         const char*         title );
  795. extern void id3tag_set_artist(
  796.         lame_global_flags*  gfp,
  797.         const char*         artist );
  798. extern void id3tag_set_album(
  799.         lame_global_flags*  gfp,
  800.         const char*         album );
  801. extern void id3tag_set_year(
  802.         lame_global_flags*  gfp,
  803.         const char*         year );
  804. extern void id3tag_set_comment(
  805.         lame_global_flags*  gfp,
  806.         const char*         comment );
  807. extern void id3tag_set_track(
  808.         lame_global_flags*  gfp,
  809.         const char*         track );
  810.  
  811. /* return non-zero result if genre name or number is invalid */
  812. extern int id3tag_set_genre(
  813.         lame_global_flags*  gfp,
  814.         const char*         genre );
  815.  
  816. /***********************************************************************
  817. *
  818. *  list of valid bitrates [kbps] & sample frequencies [Hz].
  819. *  first index: 0: MPEG-2   values  (sample frequencies 16...24 kHz) 
  820. *               1: MPEG-1   values  (sample frequencies 32...48 kHz)
  821. *               2: MPEG-2.5 values  (sample frequencies  8...12 kHz)
  822. ***********************************************************************/
  823. extern const int      bitrate_table    [3] [16];
  824. extern const int      samplerate_table [3] [ 4];
  825.  
  826.  
  827.  
  828. /* maximum size of mp3buffer needed if you encode at most 1152 samples for
  829.    each call to lame_encode_buffer.  see lame_encode_buffer() below  
  830.    (LAME_MAXMP3BUFFER is now obsolete)  */
  831. #define LAME_MAXMP3BUFFER   16384
  832.  
  833.  
  834. #if defined(__cplusplus)
  835. }
  836. #endif
  837. #endif /* LAME_LAME_H */
  838.